package com.qiguliuxing.dts.service.seckill.model;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 用户解析秒杀的缓存订单
 * @author qiguliuxing
 */
@Data
public class SeckillCacheOrder {

    /**
     * 秒杀订单数据，简要格式： {userId}:{seckillGoodsId}:{productId}:{productNum}:{oderIds多个逗号分隔，支持不限秒杀次数的配置}
     */
    private String briefInfo;

    private Integer userId;

    private Integer seckillGoodsId;

    private Integer productId;

    private Integer productNum;

    private String orderIds;

    private boolean hasOrder;

    public SeckillCacheOrder(String briefInfo) {
        if (StringUtils.isNotBlank(briefInfo)) {
            String[] briefInfoArr = briefInfo.split(":");
            this.userId = Integer.parseInt(briefInfoArr[0]);
            this.seckillGoodsId = Integer.parseInt(briefInfoArr[1]);
            this.productId = Integer.parseInt(briefInfoArr[2]);
            this.productNum = Integer.parseInt(briefInfoArr[3]);

            // 默认 未支付订单
            this.hasOrder = false;

            if (briefInfoArr.length > 4) {
                this.orderIds = briefInfoArr[4];
                if (StringUtils.isNotBlank(this.orderIds)) {
                    this.hasOrder = true;
                }
            }
        }
    }

}
